<template>
  <div class="page-wrap1">
    <Head
      title="告警信息"
      isBack
      v-if="
        data.detailData.alarmSettingType == 1 ||
        data.detailData.alarmSettingType == 2
      "
    >
      <template #content>
        <Detail
          :columns="1"
          :form="
            data.detailData.alarmSettingType == 1 ? detailForm : detailForm1
          "
          :detail="data.detailData"
          align="left"
        ></Detail>
      </template>
    </Head>

    <Head
      title="告警信息"
      isBack
      v-if="
        data.detailData.alarmSettingType == 3 ||
        data.detailData.alarmSettingType == 4
      "
    >
      <template #content>
        <Detail
          :columns="1"
          :form="
            data.detailData.alarmSettingType == 3 ? detailForm2 : detailForm3
          "
          :detail="data.detailData"
          align="left"
        ></Detail>
      </template>
    </Head>

    <Head title="告警设置" v-if="data.detailData.alarmSettingType == 1">
      <template #content>
        <div class="message-card">
          <div class="message-title">电桩充电告警</div>
          <el-form
            ref="ruleFormRef1"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template v-for="(sitem, index) in optionsS.dataForm" :key="index">
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <el-input
                    v-model.trim="sitem.threshold"
                    style="width: 280px"
                    maxlength="20"
                    disabled
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
        <div class="message-card">
          <div class="message-title">车辆告警</div>
          <el-form
            ref="ruleFormRef2"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.carDataForm"
              :key="index"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <el-input
                    v-model.trim="sitem.threshold"
                    style="width: 280px"
                    maxlength="20"
                    disabled
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
        <div class="message-card">
          <div class="message-title">连续启动失败告警</div>
          <el-form
            ref="ruleFormRef3"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.failDataForm"
              :key="`${index}`"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <el-input
                    v-model.trim="sitem.threshold"
                    style="width: 280px"
                    maxlength="20"
                    disabled
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData1"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
      </template>
    </Head>

    <Head title="告警设置" v-if="data.detailData.alarmSettingType == 2">
      <template #content>
        <div class="message-card">
          <div class="message-title">账户告警</div>
          <el-form
            ref="ruleFormRef4"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.accountDataForm"
              :key="index"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <el-input
                    v-model.trim="sitem.threshold"
                    style="width: 280px"
                    maxlength="20"
                    disabled
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData1"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
      </template>
    </Head>

    <Head title="告警设置" v-if="data.detailData.alarmSettingType == 3">
      <template #content>
        <div class="message-card">
          <div class="message-title">异常停充告警</div>
          <el-form
            ref="ruleFormRef5"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.abnormalForm"
              :key="index"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <div style="width: 280px"></div>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData1"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
        <div class="message-card">
          <div class="message-title">连续启动失败告警</div>
          <el-form
            ref="ruleFormRef3"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.failDataForm"
              :key="`${index}`"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable1">
                  <el-input
                    v-model.trim="sitem.threshold"
                    style="width: 280px"
                    maxlength="20"
                    disabled
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData1"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
      </template>
    </Head>
    <Head title="告警设置" v-if="data.detailData.alarmSettingType == 4">
      <template #content>
        <div class="message-card">
          <div class="message-title">电桩离线告警</div>
          <el-form
            ref="ruleFormRef6"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.plieDataForm"
              :key="`${index}`"
            >
              <div class="flex-form">
                <el-form-item
                  :label="sitem.dataFormLable"
                  :prop="'plieDataForm.' + index + '.threshold'"
                  :rules="sitem.itemRules"
                >
                  <el-input
                    v-model.trim="sitem.threshold"
                    placeholder="请输入"
                    style="width: 280px"
                    maxlength="20"
                  >
                    <template #prepend>{{ sitem.labelName }}</template>
                    <template #append>{{ sitem.unit }}</template>
                  </el-input>
                </el-form-item>
                <el-form-item
                  label=""
                  :prop="sitem.alarmCheckType"
                  v-if="sitem.threshold"
                >
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData1"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
        <div class="message-card">
          <div class="message-title">电桩故障告警</div>
          <el-form
            ref="ruleFormRef7"
            label-width="140px"
            class="edit-form-wrap"
          >
            <template
              v-for="(sitem, index) in optionsS.plieFaultDataForm"
              :key="index"
            >
              <div class="flex-form">
                <el-form-item :label="sitem.dataFormLable">
                  <div style="width: 280px"></div>
                </el-form-item>
                <el-form-item label="" :prop="sitem.alarmCheckType">
                  <el-checkbox-group v-model="sitem.alarmCheckType">
                    <el-checkbox
                      v-for="item in optionsS.settingData"
                      :key="item.value"
                      :label="item.label"
                      :disabled="true"
                    >
                    </el-checkbox>
                  </el-checkbox-group>
                </el-form-item>
              </div>
            </template>
          </el-form>
        </div>
      </template>
    </Head>
  </div>
</template>
 
<script lang="ts" setup>
import Head from '@/components/head/index.vue';
import Detail from '@/components/form/detail.vue';
import { getAlarmSet } from '@/service/apis/alarm';
import { queryDicByParent } from '@/service/apis/api';

const route = useRoute();
const {
  query: { id },
} = route;

let optionsS = reactive({
  settingData: [
    {
      label: '是否告警',
      value: '1',
    },
    {
      label: '告警短信',
      value: '2',
    },
    {
      label: '自动停充',
      value: '3',
    },
  ],
  settingData1: [
    {
      label: '是否告警',
      value: '1',
    },
    {
      label: '告警短信',
      value: '2',
    },
  ],
  dataForm: [] as any,
  carDataForm: [] as any,
  failDataForm: [] as any,
  accountDataForm: [] as any,
  abnormalForm: [] as any,
  plieDataForm: [] as any,
  plieFaultDataForm: [] as any,
});

const data = reactive({
  detailData: {} as any,
});

optionsS.dataForm = [
  {
    dataFormLable: '枪线温度过高',
    labelName: '一级警告阈值',
    unit: '℃',
    alarmType: 1,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: '℃',
    alarmType: 1,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: '℃',
    alarmType: 1,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '枪线温度过低',
    labelName: '一级警告阈值',
    unit: '℃',
    alarmType: 2,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: '℃',
    alarmType: 2,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: '℃',
    alarmType: 2,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '充电电压过高',
    labelName: '一级警告阈值',
    unit: 'V',
    alarmType: 3,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'V',
    alarmType: 3,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: 'V',
    alarmType: 3,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '充电电压过低',
    labelName: '一级警告阈值',
    unit: 'V',
    alarmType: 4,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'V',
    alarmType: 4,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: 'V',
    alarmType: 4,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '充电电流过高',
    labelName: '一级警告阈值',
    unit: 'A',
    alarmType: 5,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'A',
    alarmType: 5,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: 'A',
    alarmType: 5,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '充电电流过低',
    labelName: '一级警告阈值',
    unit: 'A',
    alarmType: 6,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'A',
    alarmType: 6,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: 'A',
    alarmType: 6,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '输入功率不足',
    labelName: '一级警告阈值',
    unit: 'kW',
    alarmType: 7,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'kW',
    alarmType: 7,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
];

optionsS.carDataForm = [
  {
    dataFormLable: '电池电量监控',
    labelName: '一级警告阈值',
    unit: 'KWH',
    alarmType: 13,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: 'KWH',
    alarmType: 13,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: 'KWH',
    alarmType: 13,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: 'SOC监控',
    labelName: '一级警告阈值',
    unit: '%',
    alarmType: 14,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: '%',
    alarmType: 14,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: '%',
    alarmType: 14,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '电池温度监控',
    labelName: '一级警告阈值',
    unit: '℃',
    alarmType: 15,
    alarmLevel: 1,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '二级警告阈值',
    unit: '℃',
    alarmType: 15,
    alarmLevel: 2,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
  {
    dataFormLable: '',
    labelName: '三级警告阈值',
    unit: '℃',
    alarmType: 15,
    alarmLevel: 3,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
];

optionsS.failDataForm = [
  {
    dataFormLable: '单终端',
    dataFormLable1: '单用户',
    labelName: '连续失败',
    unit: '次',
    alarmType: 12,
    alarmLevel: 0,
    prop: 'threshold',
    threshold: '',
  },
];

optionsS.accountDataForm = [
  {
    dataFormLable: '账户余额告警',
    labelName: '警告阈值',
    unit: '元',
    alarmType: 10,
    alarmLevel: 0,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
];

optionsS.abnormalForm = [
  {
    dataFormLable: '异常停充告警',
    labelName: '异常停充告警',
    alarmType: 11,
    alarmLevel: 0,
    isNotify: false,
    isAlarm: false,
  },
];

optionsS.plieDataForm = [
  {
    dataFormLable: '电桩离线告警',
    labelName: '离线时长',
    unit: '分钟',
    alarmType: 8,
    alarmLevel: 0,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
    prop: 'threshold',
    threshold: '',
  },
];

optionsS.plieFaultDataForm = [
  {
    dataFormLable: '电桩故障告警',
    alarmType: 9,
    alarmLevel: 0,
    isNotify: false,
    isStopCharging: false,
    isAlarm: false,
  },
];

const detailForm = reactive([
  {
    label: '设置名称',
    prop: 'alarmSettingName',
  },
  {
    label: '告警类型',
    prop: 'alarmSettingType',
    dic: [] as any,
    type: Number,
  },
  {
    label: '适用电桩',
    prop: 'relateTree',
    comName: 'tree',
    dic: [] as any,
  },
  {
    label: '通知号码',
    prop: 'operatorName',
    template: (row: any) => {
      if (row.notifyNumbers && row.notifyNumbers.length > 1) {
        return `${row.notifyNumbers.join(',')}`;
      } else if (row.notifyNumbers && row.notifyNumbers.length == 1) {
        return row.notifyNumbers;
      } else {
        return '--';
      }
    },
  },
]);
const detailForm1 = reactive([
  {
    label: '设置名称',
    prop: 'alarmSettingName',
  },
  {
    label: '告警类型',
    prop: 'alarmSettingType',
    dic: [] as any,
    type: Number,
  },
  {
    label: '适用企业',
    prop: 'relateTree',
    comName: 'tree',
    dic: [] as any,
  },
  {
    label: '通知号码',
    prop: 'notifyNumbers',
    template: (row: any) => {
      if (row.notifyNumbers && row.notifyNumbers.length > 1) {
        return `${row.notifyNumbers.join(',')}`;
      } else if (row.notifyNumbers && row.notifyNumbers.length == 1) {
        return row.notifyNumbers;
      } else {
        return '--';
      }
    },
  },
]);

const detailForm2 = reactive([
  {
    label: '设置名称',
    prop: 'alarmSettingName',
  },
  {
    label: '告警类型',
    prop: 'alarmSettingType',
    dic: [] as any,
    type: Number,
  },
]);

const detailForm3 = reactive([
  {
    label: '设置名称',
    prop: 'alarmSettingName',
  },
  {
    label: '告警类型',
    prop: 'alarmSettingType',
    dic: [] as any,
    type: Number,
  },
  {
    label: '通知号码',
    prop: 'notifyNumbers',
    template: (row: any) => {
      if (row.notifyNumbers && row.notifyNumbers.length > 1) {
        return `${row.notifyNumbers.join(',')}`;
      } else if (row.notifyNumbers && row.notifyNumbers.length == 1) {
        return row.notifyNumbers;
      } else {
        return '--';
      }
    },
  },
]);

queryDicByParent({
  listDtos: ['AlarmSettingType'],
}).then((res: any) => {
  detailForm[1].dic = [...res.AlarmSettingType];
  detailForm1[1].dic = [...res.AlarmSettingType];
  detailForm2[1].dic = [...res.AlarmSettingType];
  detailForm3[1].dic = [...res.AlarmSettingType];
});

getAlarmSet({ id: id }).then((res: any) => {
  data.detailData = res;
  detailForm[2].dic = res.relateTree;
  detailForm1[2].dic = res.relateTree;
  const alarmTerms = res.alarmTerms;

  // 判断充电安全告警时告警设置的数据回显
  if (data.detailData.alarmSettingType == '1') {
    // 电桩充电告警数据回显，判断alarmType和alarmLevel相同时，数组合并
    const arrs = alarmTerms.slice(0, 20).map((item: any) => {
      // console.log('item=========', item);
      const data = optionsS.dataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );
      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }

      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }

      if (item.isStopCharging) {
        item.alarmCheckType.push('自动停充');
      }
      return { ...data[0], ...item };
    });
    optionsS.dataForm = arrs;
    console.log(optionsS.dataForm);

    // 车辆告警数据回显，判断alarmType和alarmLevel相同时，数组合并
    const arrs1 = alarmTerms.slice(21, 30).map((item: any) => {
      console.log(item);
      console.log(optionsS.carDataForm);
      const carData = optionsS.carDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );
      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }

      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }

      if (item.isStopCharging) {
        item.alarmCheckType.push('自动停充');
      }
      return { ...carData[0], ...item };
    });
    optionsS.carDataForm = arrs1;

    // 连续启动失败告警告警数据回显，判断alarmType和alarmLevel相同时，数组合并
    const arrs2 = alarmTerms.slice(20, 21).map((item: any) => {
      const failData = optionsS.failDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );
      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }
      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      return { ...failData[0], ...item };
    });

    optionsS.failDataForm = arrs2;
  }

  if (data.detailData.alarmSettingType == '2') {
    const arrs = alarmTerms.map((item: any) => {
      const data = optionsS.accountDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );
      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }

      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      return { ...data[0], ...item };
    });
    optionsS.accountDataForm = arrs;
    console.log(optionsS.accountDataForm);
  }

  if (data.detailData.alarmSettingType == '3') {
    const arrs1 = alarmTerms.slice(0, 1).map((item: any) => {
      const abnormaData = optionsS.abnormalForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );

      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }
      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      return { ...abnormaData[0], ...item };
    });
    optionsS.abnormalForm = arrs1;

    const arrs2 = alarmTerms.slice(1, 2).map((item: any) => {
      const failData = optionsS.failDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );

      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }
      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      return { ...failData[0], ...item };
    });
    optionsS.failDataForm = arrs2;
  }

  if (data.detailData.alarmSettingType == '4') {
    const arrs1 = alarmTerms.slice(0, 1).map((item: any) => {
      const abnormaData = optionsS.plieDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );

      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }
      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      return { ...abnormaData[0], ...item };
    });
    optionsS.plieDataForm = arrs1;

    const arrs2 = alarmTerms.slice(1, 2).map((item: any) => {
      const plieFaultData = optionsS.plieFaultDataForm.filter(
        (i: any) =>
          item.alarmType == i.alarmType && item.alarmLevel == i.alarmLevel
      );

      item.alarmCheckType = [];
      if (item.isAlarm) {
        item.alarmCheckType.push('是否告警');
      }
      if (item.isNotify) {
        item.alarmCheckType.push('告警短信');
      }
      if (item.isStopCharging) {
        item.alarmCheckType.push('自动停充');
      }
      return { ...plieFaultData[0], ...item };
    });
    optionsS.plieFaultDataForm = arrs2;
  }
});
</script>
<style lang="scss" scoped>
.message-card {
  border: 1px solid var(--el-color-primary);
  padding: 14px 0;
  margin: 16px;

  .message-title {
    padding-left: 12px;
    font-size: 12px;
    color: var(--el-color-primary);
    font-weight: 500;
  }

  .message-textarea {
    width: 95% !important;
  }

  .card-edit {
    position: absolute;
    right: 5%;
    top: 0;
    margin-right: 10px;
    font-size: 12px;
    cursor: pointer;
  }

  .card-save {
    display: flex;
    position: absolute;
    right: 5%;
    top: 0;
    margin-right: 10px;
    cursor: pointer;
  }
}

.flex-form {
  display: flex;
}
</style>
